package com.gitee.huxing.course.conc.conc02.atomic;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.conc02
 * @ClassName: SyncCount
 * @Author: huxing
 * @DateTime: 2021-08-23 上午9:59
 */
public class SyncCount {

    private int num = 0;

    private Lock lock = new ReentrantLock(true);

    public int add(){
        lock.lock();
        try {
            return num++;
        } finally {
            lock.unlock();
        }
    }

    public int getNum(){
        return num;
    }
}
